<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="applogotext">
        <el-input
          v-model="queryParams.applogotext"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
          id="applogotext"
        />
      </el-form-item>
      <el-form-item label="logo" prop="applogotype">
        <el-select v-model="queryParams.applogotype" placeholder="请选择项目LOGO类型" id="applogotype" @change="handleQuery" clearable>
          <el-option
            v-for="dict in dict.type.sys_logo_type"
            :key="dict.value"
            :label="dict.label"
            :value="parseInt(dict.value)"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目面积" prop="apparea">
        <el-input
          v-model="queryParams.apparea"
          placeholder="请输入项目面积"
          clearable
          @keyup.enter.native="handleQuery"
          id="apparea"
        />
      </el-form-item>
      <el-form-item label="项目时间" prop="appdate">
        <el-date-picker clearable
          v-model="queryParams.appdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择项目日期"
          id="appdate">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="项目人数" prop="appman">
        <el-input
          v-model="queryParams.appman"
          placeholder="请输入项目人数"
          clearable
          @keyup.enter.native="handleQuery"
          id="appman"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:appinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:appinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:appinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:appinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="项目ID" align="center" prop="appid" width="60"/>-->
      <el-table-column label="项目数据库名称" align="center" prop="appname" width="120"/>
      <el-table-column label="LOGO类型" align="center" prop="applogotype" width="120">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_logo_type" :value="scope.row.applogotype"/>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="applogotext" />
      <el-table-column label="LOGO图片显示" align="center" prop="applogoimg" :show-overflow-tooltip="true" width="460"/>
      <el-table-column label="项目面积" align="center" prop="apparea" width="80"/>
      <el-table-column label="项目创建时间" align="center" prop="appdate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.appdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目人数" align="center" prop="appman" width="80"/>
      <el-table-column label="项目图片显示" align="center" prop="apppic" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="${comment}" align="center" prop="appreserve1" />
      <el-table-column label="${comment}" align="center" prop="appreserve2" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:appinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:appinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="数据库名" prop="appname">
              <el-select v-model="form.appname" placeholder="请选择所属项目数据库名" clearable required="true">
                <el-option
                  v-for="app in appOptions"
                  :key="app.appName"
                  :label="app.appName"
                  :value="app.appName"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="LOGO类型" prop="applogotype" label-width="80">
              <el-select v-model="form.applogotype" placeholder="请选择项目LOGO类型" clearable>
                <el-option
                  v-for="dict in dict.type.sys_logo_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="applogotext" label-width="80" style="margin-left: 10px">
              <el-input v-model="form.applogotext" placeholder="请输入项目名称" style="width: 360px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="LOGO路径" prop="applogoimg" label-width="80">
              <el-input v-model="form.applogoimg" placeholder="请输入项目logo图片路径" style="width: 360px"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目面积" prop="apparea">
              <el-input v-model="form.apparea" placeholder="请输入项目面积"  style="width: 360px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目时间" prop="appdate">
              <el-date-picker clearable
                              v-model="form.appdate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择项目日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目人数" prop="appman">
              <el-input v-model="form.appman" placeholder="请输入项目人数"  style="width: 360px"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目图片" prop="apppic">
              <el-input v-model="form.apppic" placeholder="请输入项目图片路径"  style="width: 360px"/>
            </el-form-item>
          </el-col>
        </el-row>

<!--        <el-form-item label="${comment}" prop="appreserve1">
          <el-input v-model="form.appreserve1" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="appreserve2">
          <el-input v-model="form.appreserve2" placeholder="请输入${comment}" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppinfo, getAppinfo, delAppinfo, addAppinfo, updateAppinfo,appManagerSelect } from "@/api/system/appinfo";

export default {
  name: "Appinfo",
  dicts: ['sys_logo_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目信息表格数据
      appinfoList: [],
      // 项目数据选项
      appOptions: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        appname: null,
        appman: null,
        apparea: null,
        appdate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getAppManagerSelect();
  },
  methods: {
    /** 查询项目信息列表 */
    getList() {
      this.loading = true;
      listAppinfo(this.queryParams).then(response => {
        this.appinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询项目类型 */
    getAppManagerSelect() {
      appManagerSelect().then(response => {
        this.appOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        appid: null,
        appname: null,
        applogotype: null,
        applogotext: null,
        applogoimg: null,
        apppic: null,
        appman: null,
        apparea: null,
        appdate: null,
        appreserve1: null,
        appreserve2: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.appid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const appid = row.appid || this.ids
      getAppinfo(appid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.appid != null) {
            updateAppinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAppinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const appids = row.appid || this.ids;
      this.$modal.confirm('是否确认删除项目信息编号为"' + appids + '"的数据项？').then(function() {
        return delAppinfo(appids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/appinfo/export', {
        ...this.queryParams
      }, `appinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
